'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 6_study_mult_model_config.py
* @Time: 2025/7/27
* @All Rights Reserve By Brtc
'''
import dotenv
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import ConfigurableField
from langchain_openai import ChatOpenAI

"""6、Runnable 组件动态替换运行时组件    a、configurable_alternatives 方法与使用技巧"""
dotenv.load_dotenv()

# 1、创建提示词模板定义默认大语言模型
prompt = ChatPromptTemplate.from_template("{query}")
llm = ChatOpenAI(model = "gpt-3.5-turbo-16k").configurable_alternatives(
    ConfigurableField(id = "llm"),
    gpt4 = ChatOpenAI(model = "gpt-4o"),
    gpt4mini = ChatOpenAI(model = "gpt-4o-mini"),
)

# 构建链
chain = prompt|llm|StrOutputParser()

#调用链
content = chain.invoke({"query":"你好你是Gpt 几？"}, config={"configurable":{"llm":"gpt4mini"}})
print(content)